<?php

namespace App\BO\Coupon\CouponProductSkuCheck;

use Illuminate\Support\Facades\Log;

class UnuseProductSkuTitleCheck implements ICouponProductSkuCheck
{
    public static function check(CouponProductSkuCheckMeta $checkMeta, \Closure $next)
    {
        $couponCodeEntity = $checkMeta->getCouponEntity();
        $title = $checkMeta->getProductSkuEntity()->getTitle();

        $unuseProductSkuTitle = $couponCodeEntity->getUnuseProductSkuTitle();
        if ($unuseProductSkuTitle) {
            if (in_array($title, explode(',', $unuseProductSkuTitle))) {
                Log::info('优惠券' . $couponCodeEntity->getId() . 'unuse_sku_title 检测不符合');
                $checkResultWrapper = new CheckResultWrapper($checkMeta->getCouponEntity());
                $checkResultWrapper->setMessage('当前产品不可使用');
                return $checkResultWrapper;
            }
        }

        return $next($checkMeta);
    }
}
